#include <linux/init.h>
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/ioport.h>


static void dev_release(struct device * dev);

struct plat_dev
{
    struct platform_device      pdev;
    int                         flags;
};

static struct resource  g_res[] = {
   [0] = {
        .start  = 0x56000050,
	    .end    = 0x56000058,
	    .name   = "led_addr",
	    .flags  = IORESOURCE_MEM,
	    .parent = NULL,
	    .sibling = NULL,
	    .child  = NULL,
    },
  [1] = {
         .start  = 4,               //用于指示是GPF4,GPF5,GPF6中的哪个
         .end    = 4,               //用于指示GPFDAT寄存器中的哪个pin脚
         .name   = "led_pin",
         .flags  = IORESOURCE_IRQ,
         .parent = NULL,
         .sibling = NULL,
         .child  = NULL,
     },

};


static struct plat_dev  g_pdev = {
    .pdev   =  {
        .name   =   "platform_leds",
	    .id     =   -1,
	    .dev = {
	        .bus        = &platform_bus_type,
	        .release    = dev_release,
	    },
	    .num_resources  = ARRAY_SIZE(g_res),
	    .resource   = g_res,
    },
    .flags  = -1,
};

static void dev_release(struct device * dev)
{
    printk(KERN_INFO "Release led device.\n");
}


static int __init leddevdrv_init(void)
{
    printk(KERN_INFO "The driver 'leddevdrv' is inserted!\n");
    int ret = platform_device_register(&g_pdev.pdev);
    if(ret != 0)
    {
        printk(KERN_INFO "Register platform led device driver failed!\n");
        return -EINVAL;
    }
    g_pdev.flags = 0;

    return 0;
}
static void __exit leddevdrv_exit(void)
{
    printk(KERN_INFO "The driver 'leddevdrv' is removed!\n");
    if(!g_pdev.flags)
    {
        platform_device_unregister(&g_pdev.pdev);
    }
}



module_init(leddevdrv_init);
module_exit(leddevdrv_exit);


MODULE_LICENSE("GPL");

